#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
This file is part of playlistbs.

@author: Romain RICHARD
@contact: romain.richard.IT.engineer@gmail.com
@version: 2.0
@copyright: GPLv3

@change: 2012-09-17: Used pylint to clean up the code
@change: 2011-08-20: Changed the default_v{f,o}_subs attributes to prioritize
                     subtitles
@change: 2011-08-06: Added the __eq__ method
@change: 2011-08-05: Changed the way to deal with attributes
@change: 2011-08-04: Added the is_empty method
@change: 2011-08-01: Creation of the file
"""


class Show(object):
    """A show."""

    def __init__(self, title="", url="", vf_subs=1, vo_subs=2):
        self.title = title
        self.url = url
        self.vf_subs = vf_subs
        self.vo_subs = vo_subs

    def __eq__(self, other):
        return self.__dict__ == other.__dict__

    def __non_zero__(self):
        return any(self.title, self.url)

    def create_node(self, shows):
        """Create an xml node for a show.

        @type shows: Document
        @param shows: A Document containing the shows of the member

        @rtype: Node
        @return: A Node containing the show's infos

        """
        node_show = shows.createElement("show")

        title = shows.createElement("title")
        node_show.appendChild(title)
        title_value = shows.createTextNode(self.title)
        title.appendChild(title_value)

        url = shows.createElement("url")
        node_show.appendChild(url)
        url_value = shows.createTextNode(self.url)
        url.appendChild(url_value)

        subs = shows.createElement("subs")
        node_show.appendChild(subs)

        vf_subs = shows.createElement("VF")
        subs.appendChild(vf_subs)
        vf_value = shows.createTextNode(str(self.vf_subs))
        vf_subs.appendChild(vf_value)

        vo_subs = shows.createElement("VO")
        subs.appendChild(vo_subs)
        vo_value = shows.createTextNode(str(self.vo_subs))
        vo_subs.appendChild(vo_value)

        return node_show
